Function.RegisterNamespace("System.Script");

System.Script.ScriptLoader=new function(){
    var _strategyManager;

    // Public Members
    this.Strategies;
    
    // ctor
    function ScriptLoader(){
        this.Strategies=_strategyManager=new System.Script.Strategy.StrategyManager();
    }
    ScriptLoader.apply(this,arguments);

    // ILoadStrategy Members
    this.Import=function(path,callback){
        if(path==undefined||!Object.IsType(Function,path.toString))throw new Error("System.Script.ScriptLoader.Import: 'path' must be convertible to String.");
        path=path.toString();
        if(arguments.length>1){
            if(!Object.IsType(Function,callback))throw new Error("System.Script.ScriptLoader.Import: 'callback' must be a valid Function pointer.");
        }
        try{
            return _strategyManager.Get(this).Import(path,callback);
        }catch(e){
            throw new Error(String.Format("System.Script.ScriptLoader.Import: There was an error importing script '{0}'.\nError: {1}",path,e));
        }
    };

    this.ImportJson=function(path,callback){
        if(path==undefined||!Object.IsType(Function,path.toString))throw new Error("System.Script.ScriptLoader.ImportJson: 'path' must be convertible to String.");
        path=path.toString();
        if(arguments.length>1){
            if(!Object.IsType(Function,callback))throw new Error("System.Script.ScriptLoader.ImportJson: 'callback' must be a valid Function pointer.");
        }
        try{
            return _strategyManager.Get(this).ImportJson(path,callback);
        }catch(e){
            throw new Error(String.Format("System.Script.ScriptLoader.ImportJson: There was an error importing json '{0}'.\nError: {1}",path,e));
        }
    };
    
    this.Load=function(source){
        if(source==undefined||!Object.IsType(Function,source.toString))throw new Error("System.Script.ScriptLoader.Load: 'source' must be convertible to String.");
        source=source.toString();
        try{
            return _strategyManager.Get(this).Load(source);
        }catch(e){
            throw new Error(String.Format("System.Script.ScriptLoader.Load: There was an error loading script.\nError: {0}",e));
        }
    };
        
};

System.Script.ScriptLoader.constructor.Implement(System.Script.ScriptLoadStrategy.ILoadStrategy,'System.Script.ScriptLoader');
